<?php
      $buzzr_current_user = buzzrs_current_user();
      $current_user_id = $buzzr_current_user['user_id'];
	  $deal_id = $this->get_field('id');
      $tags_deal = get_deal_tags($this);
      $city_name = strtolower(get_city($this));
      $camp_link = "{@camp_link}";
      $deal_link = BUZZR_URL.'/deals/'.$camp_link;
      $is_coupon = "{@coupon}";
      $deal_sale = "{@sale}";
      $deal_name = "{@name}";
      $discount = str_replace('%','',"{@disper}");
      $deal_details = strip_tags("{@short}");
      $cat_name = "{@camp_cat.name}";
      $cat_link = BUZZR_URL.'/'."{@camp_cat.url}";
      $cat_link_local = BUZZR_URL.'/localoffers/'.$city_name.'/'."{@camp_cat.url}";
      $deal_expires = "{@camp_end}";
      $count = $this->getRowNumber();
            
      $merchant_name = ucwords("{@brand.name}");
      $merchant = 'Merchant: <a href="'.BUZZR_URL.'/brands/'."{@brand.brandurl}".'">'.$merchant_name.'</a>';
      
      $provider_name = ucwords("{@deal_provider.name}");
      $provider = 'By: <a href="'.BUZZR_URL.'/brands/'."{@deal_provider.brandurl}".'">'.$provider_name.'</a>';
      
      if(empty($provider_name)){
        $provider_name = ucwords("{@added_by_user.name}");
        $provider = 'By: <a href="'.BUZZR_URL.'/member/'."{@added_by_user.slug}".'" >'.$provider_name.'</a>';
        if(!empty($provider_name)){
        	$is_owner_of_deal = is_deal_owner($provider_name);
        }
      }
      
      $deal_title = substr($deal_name,0,150);
      $deal_detail = $deal_details.'<br /><br /><br />Visit: <a href="'.$deal_link.'" title="'.$deal_name.'">'.$merchant_name.'</a> deal';
      $image = get_image($this);
      if(trim($provider_name) == 'Delivery Chef'){
      	$deal_link_ga = get_redirect($this, 'Delivery Chef');
      }else{
      	$deal_link_ga = get_redirect($this);
      }
      
      
      /* Code for User Likes */
	  $user_likes = $this->get_field('user_likes.id');
	  if(empty($user_likes)){
		$count_likes = '<b>0 Saves</b>';
	  }else{
		$count_likes = '<b>'.count($user_likes).' Saves</b>';
	  }
        
	  $does_user_like = buzzr_saved_deal($buzzr_current_user['deals_liked'],$deal_id);
	  /* Code for User Likes */

?> 
        <li>
            <div class="deal">
                <div class="images fleft">
	                <?php if($image != TRUE){ ?>
	                <a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else{ echo $deal_link_ga; } ?>"><div class="image_filler"><p><?php echo $merchant_name;?></p></div></a>
	                <?php }else{ ?>
	               	 <a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else{ echo $deal_link_ga; } ?>"><img src="<?php echo $image; ?>" alt="<?php echo $tags_deal; ?>" /></a>
	               	 <?php } ?>
             
	                <div class="icon">
	                	<?php if(!empty($discount)){ ?>
	                	<span class="discount"><?php echo $discount; ?>% off</span>
	                	<img src="<?php echo BUZZR_THEME_URL.'/img/discount.png'; ?>" width="70px" height="70px">
	                	<?php } ?>
	                </div>
                </div>
              <div class="deal_list_details">
                <p class="deal_title">
                	<a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else{ echo $deal_link_ga; } ?>"><?php echo $deal_title; ?></a>
                	<?php if($is_owner_of_deal == 1){ echo '   --><span style="font-size: 11px; font-style: italic;"><a href="'.BUZZR_URL.'/edit-offer/'.$camp_link.'">Edit Offer</a></span>'; } ?>
                </p>
                <p class="merchant_name"><?php if(!empty($merchant_name)){ echo $merchant; }?></p>
                <div class="get_deal">
                 	<a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else{ echo $deal_link_ga; } ?>"><img src="<?php if($is_coupon == 1){ echo BUZZR_THEME_URL.'/img/grab_coupon.png'; }else{ echo BUZZR_THEME_URL.'/img/grab.png';} ?>"/></a>
	                <?php /*if (!empty($deal_expires)){?> <p class="expiry">Expires In:</p><?php }*/?> 
	                <?php if (!empty($deal_details)){?> <p class="more">Deal Details</p> <?php }?>
                    <div class="clear"></div> 
                </div>  
                <div class="details"><?php echo $deal_detail; ?></div>                    
             </div>
             <div class="clear"></div>
             <div class="deal_info">
             	<div class="info">
                  <?php if(!empty($cat_name)){ ?><p class="info_name">Category: <a href="<?php if($deal_sale){ echo $cat_link_local; }else{ echo $cat_link; } ?>"><?php echo $cat_name; ?></a></p><?php } ?>
	              <?php if(!empty($provider_name)){ ?><p class="info_name"><?php echo $provider; ?></p><?php } ?>
	              <div class="clear"></div>
	             </div>
	            <div class="social">
	            	<?php if(!is_user_logged_in()){ ?>
	            	
	            		<a class="simplemodal-login"><img src="<?php echo BUZZR_THEME_URL.'/img/save.png'; ?>" /></a>
	            		<span class="number"><?php echo $count_likes; ?></span>
	            		
	            	<?php }else{ 
	            				if($does_user_like == 0){
	            	?>
	            				
	            					<span id="<?php echo $deal_id.'_'.$current_user_id; ?>" class="save"><img src="<?php echo BUZZR_THEME_URL.'/img/save.png'; ?>" /></span>
	            					<span id="result_<?php echo $deal_id; ?>" class="number"><?php echo $count_likes; ?></span>
	            				
	            	<?php 		}else{ ?>
	            			
	            					<span id="result_<?php echo $deal_id; ?>" class="number"><?php echo $count_likes; ?></span>
	            				
	            	<?php 		} 
	            	}
	            	?>
	            	<?php /*<div class="google"><g:plusone size="small" href="<?php echo $deal_link; ?>"></g:plusone></div>
	            	<div class="fb"><iframe src="http://www.facebook.com/plugins/like.php?app_id=228219050523496&amp;href=<?php echo $deal_link; ?>&amp;send=false&amp;layout=button_count&amp;width=300&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe></div> */ ?>
	            </div>
	            <div class="clear"></div>
	         </div>      
            </div>
            
        </li>
        
        <?php 
        
        if ($count > 1){
        	if ($count == 2){
	
        ?>
        	<div class="clear"></div>
        	<div class="adsense">
	        	<script type="text/javascript"><!--
				google_ad_client = "ca-pub-3655588719499040";
				/* ListPage H Banner */
				google_ad_slot = "6102829002";
				google_ad_width = 468;
				google_ad_height = 60;
				//-->
				</script>
				<script type="text/javascript"
				src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
				</script>
              </div>
          <?php 
        	}		
      	}
      	
      	if ($count > 8){
        	if ($count == 9){ ?>
        	<div class="clear"></div>
        	<div class="adsense">
	        	<script type="text/javascript"><!--
				google_ad_client = "ca-pub-3655588719499040";
				/* ListPage H Banner */
				google_ad_slot = "6102829002";
				google_ad_width = 468;
				google_ad_height = 60;
				//-->
				</script>
				<script type="text/javascript"
				src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
				</script>
              </div>
           <?php 
        	  }		
      	   }
        
        ?>